require_relative "../Expr"

# Expression for identifiers
#
# @author Paul T.
class Calcula::Exprs::IdentExpr < Calcula::Expr

  # @param name [Calcula::Token] This token should have the type ID
  def initialize(name)
    @name = name
  end

  # @see Calcula::Expr#to_s
  # @param (see Calcula::Expr#to_s)
  # @return (see Calcula::Expr#to_s)
  def to_s(form: :src)
    case form
    when :src then
      @name.text
    when :tree then
      "(ident #{@name.text})"
    when :ruby then
      @name.text.tr("'", "_")
    else
      nil
    end
  end

  # @see Calcula::Expr#children
  # @param (see Calcula::Expr#children)
  # @return (see Calcula::Expr#children)
  def children
    []
  end
end
